package cn.javase.concurrent._并发编程._06_共享模型之无锁._原子引用._示例;

import java.math.BigDecimal;

public class DecimalAccountSafeSyn implements DecimalAccount {

    private BigDecimal balance;

    public DecimalAccountSafeSyn(String balance) {
        this.balance = new BigDecimal(balance);
    }

    @Override
    public BigDecimal getBalance() {
        return this.balance;
    }

    @Override
    public void withdraw(BigDecimal amount) {
        synchronized (this) {
            this.balance = this.balance.subtract(amount);
        }
    }

}
